package com.dc.di.util;

import java.io.File;
import java.io.FileInputStream;
import java.security.MessageDigest;

import org.apache.commons.codec.binary.Hex;

/**
* @ClassName: MD5Creater
* @Description: TODO
* @author zhangbinp
* @date Nov 17, 2011 9:03:37 PM
*/
public class MD5Creater {
	public static String doMD5(File file , int bufSize){
		FileInputStream in = null;
		try{
			MessageDigest md = MessageDigest.getInstance("MD5");
			in = new FileInputStream(file);
			byte [] buffer = new byte [bufSize];
			int len = 0;
			while((len = in.read(buffer)) != -1){
				md.update(buffer,0,len);
			}
			return Hex.encodeHexString(md.digest()).toUpperCase();
		}catch(Exception e){
			throw new RuntimeException(e);
		}finally{
			if(in!=null){
				try{
					in.close();
				}catch(Exception e){}
			}
		}
	}

}
